package com.boboPlanet.comm.utils;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/5/11
 **/
@Slf4j
public class AutoGenerateIds {
    /**
     * workerId 0~31(Long)
     * datacenterId  0~31(Long)
     */
    private static final Long WORKER_ID = 10L;
    private static final Long DATA_CENTER_ID = 10L;
    /**
     * 生成id数量
     */
    private static final Integer COUNT = 1;

    /**
     * 生成0~31的随机数
     */
    private static Long getRandom(){
        //0~31
        return (Long) (long) (int) (Math.random()*32);
    }

    /**
     * 生成随机id
     */
    public static Long getGenerateId(){
        //当机器码不够用可以通过随机数给workerId，datacenterId赋值
        //workerId = getRandom();
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(WORKER_ID, DATA_CENTER_ID);
        return idWorker.nextId();
    }
}
